<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<%@ include file="/pub/head_latest.inc"%>
    <title>Edit</title>
    <style type="text/css">
    	html,body{
    		background: #fff;
    	}
    </style>
</head>
<body style="padding-bottom:31px;">
     <form id="mainform" method="post">
     	<input type="hidden" name="commonSearchId" id="commonSearchId" value="${commsearchid}"/>
     </form> 
</div>
  <script type="text/javascript">
      var pkId = '${id}';
      function badousoft(){}
	  badousoft.ajax=function(s){
		  jQuery.ajax(s);
	  }

  	  var baseUrl = '${baseURL}/report/commsearchparams/commsearchparams';
  	var data = [
              	{id:'1',text:'是'},
              	{id:'0',text:'否'},
              ];
           //button 
      //edit add
	  var mainform = $("#mainform");
              mainform.ligerForm({ 
                  fields: [
				         { name: "id", type: "hidden" },
				         { display: "变量名称", name: "fieldName", newline: true, labelWidth: 100, width: 300, space: 30,  labelAlign:"right",type: "text" ,
				        	 	validate: { required: true, maxlength: 50}},
		        	 	 { display: "控件名称", name: "name", newline: false, labelWidth: 100, width: 300, space: 30, labelAlign:"right",type: "text" ,
			        	 	    validate: { required: true, maxlength: 50}},
				         { display: "定义搜索框", name: "searchBox", newline: true, labelWidth: 100, width: 300, space: 30,  labelAlign:"right",type: "text" ,
				        	 	validate: { required: true}, liCss:"for-user-defined"},
				         { display: "搜索框数据来源", name: "searchDataSourceDesc", newline: false, labelWidth: 100, width: 300, space: 30, labelAlign:"right",type: "select" ,
						     	options: { valueFieldID: "searchDataSource" , data:  [{id:1, text:'数据字典'}, {id:2, text:'自定义'}]}, liCss:"for-user-defined"},
		        	 	 { display: "搜索框数据", name: "searchData", newline: true, labelWidth: 100, width: 300, space: 30,  labelAlign:"right",type: "text", liCss:"for-user-defined"},
				         { display: "别名", name: "aliasName", newline: true, labelWidth: 100, width: 300, space: 30, labelAlign:"right",type: "text" ,
				        	 	validate: { required: true, maxlength: 50}, liCss:"for-sql"},
				         { display: "控件类型", name: "type", newline: false, labelWidth: 100, width: 300, space: 30, labelAlign:"right",type: "hidden"},
				         { display: "控件类型", name: "typeDesc", newline: false, labelWidth: 100, width: 300, space: 30, labelAlign:"right",type: "select" ,
				        	 options: { valueFieldID: "type" , data:  ${types}}, liCss:"for-sql"},
				         { display: "数据类型", name: "dataType", newline: true, labelWidth: 100, width: 300, space: 30, labelAlign:"right",type: "hidden"},
				         { display: "数据类型", name: "dataTypeDesc", newline: true, labelWidth: 100, width: 300, space: 30, labelAlign:"right",type: "select" ,
				        	 		options: { valueFieldID: "dataType" , data:  ${dataTypes}}, liCss:"for-sql"},
				         { display: "操作类型", name: "operatorType", newline: false, labelWidth: 100, width: 300, space: 30, labelAlign:"right",type: "hidden"},
				         { display: "操作类型", name: "operatorTypeDesc", newline: false, labelWidth: 100, width: 300, space: 30, labelAlign:"right",type: "select" ,
				        	 		options: { valueFieldID: "operatorType" , data:  ${operateTypes}}, liCss:"for-sql"},
				         { display: "数据字典值", name: "dicCode", newline: true, labelWidth: 100, width: 300, space: 30, labelAlign:"right",type: "text" ,
				        	 	validate: { maxlength: 50}, liCss:"for-sql"},
		        	 	 /* 数据库没有该字段 */
			        	 /* { display: "拼接语句", name: "isSplice", newline: false, labelWidth: 100, width: 300, space: 30, type: "select", labelAlign:"right",
								comboboxName: "IsSplice", options: {data: data},validate: { required: true, maxlength: 32}, liCss:"for-sql"}, */
						 { display: "排序", name: "priority", newline: false, labelWidth: 100, width: 300, space: 30, labelAlign:"right",type: "int" ,
						        validate: { required: true, maxlength: 50}},
			        	 { display: "默认值", name: "defaultValue", newline: true, labelWidth: 100, width: 300, space: 30, labelAlign:"right",type: "text", 
			    		   	 	validate: { maxlength: 50}}
         			],
                  toJSON: JSON2.stringify
              });
     
      //validate
     jQuery.metadata.setType("attr", "validate"); 
     LG.validate(mainform);
     //带验证、带loading的提交
     LG.submitForm = function (mainform, success, error)
     {
         if (!mainform)
             mainform = $("form:first");
         if (mainform.valid())
         {
             mainform.ajaxSubmit({
                 dataType: 'json',
                 success: success,
                 beforeSubmit: function (formData, jqForm, options)
                 {
                     //针对复选框和单选框 处理
                     $(":checkbox,:radio", jqForm).each(function ()
                     {
                         if (!existInFormData(formData, this.name))
                         {
                             formData.push({ name: this.name, type: this.type, value: this.checked });
                         }
                     });
                     for (var i = 0, l = formData.length; i < l; i++)
                     {
                         var o = formData[i];
                         if (o.type == "checkbox" || o.type == "radio")
                         {
                         	if(o.name && $.trim(o.name) != ''){
                             	o.value = $("[name=" + o.name + "]", jqForm)[0].checked ? "true" : "false";
                             }else{
                             	o.value = 'false';
                             }
                         }
                     }
                 },
                 beforeSend: function (a, b, c)
                 {
                   
                 },
                 complete: function ()
                 {
                     
                 }
             });
         }
         else
         {
             //LG.showInvalid();
         }
         function existInFormData(formData, name)
         {
             for (var i = 0, l = formData.length; i < l; i++)
             {
                 var o = formData[i];
                 if (o.name == name) return true;
             }
             return false;
         }
     };
     //save
     function FF_Save(){
         	  mainform.attr("action",baseUrl+"save/save.do?id=${id}");
         	  LG.submitForm(mainform, function (data) {
         		  var win = parent || window;
         		  win.$.ligerDialog.success("操作成功");
         		  console.info(parent.reloadGrid);
             	  parent.reloadGrid(data);
              });
    }
     //Cancel
    function FF_Cancel(){
    	var win = parent || window;
        win.LG.closeCurrentTab("CommSearchParamsEdit");
    }
 
      //After Loaded
     function FF_AfterLoaded(){
  		$("#commonSearchId").val('${commsearchid}');
  		if(parent.getReportType()==1){
  			$(".for-user-defined").hide();
  			$(".for-sql").show();
  		}else{
  			$(".for-sql").hide();
  			$(".for-user-defined").show();
  		}
     }
     

  </script>
  <script type="text/javascript">
      //load data
       LG.loadForm({mainForm: mainform, 
    	  url:baseUrl+'edit/editJSON.do?id=${id}',callback: FF_AfterLoaded});
        
  </script>
</body>
</html>